package com.fourpigeon.dao;

import com.fourpigeon.domain.BlogDaily;
import com.fourpigeon.domain.BlogDeal;
import org.apache.ibatis.annotations.*;

import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 普通Blog(日常贴)
 * 数据库相关操作
 */
@Mapper
@Repository
public interface BlogDailyDao {
    @Select("select * from tb_blog_daily where userId = #{userId} and id<#{startId} and status < 2 order by createTime DESC limit 6")
    public List<BlogDaily> getByUserId(Long userId,Long startId);
    @Select("select * from tb_blog_daily where id = #{id} and status < 2")
    public BlogDaily getById(Long id);
    @Select("select * from tb_blog_daily where status<2")
    public List<BlogDaily> getAll();
    @Update("update tb_blog_daily set likes=#{likes},icon=#{icon},userName=#{userName},comments=#{comments},type=#{type},content=#{content},images=#{images},status=#{status} where id = #{id}")
    public boolean update(BlogDaily blogDaily);

    @Update("update tb_blog_daily set comments = comments + 1 where id = #{blogId}")
    public boolean updateCommentNum(Long blogId);
    @Insert("insert into tb_blog_daily values(#{id},#{userId},#{likes},#{isLike},#{icon},#{userName},#{comments},#{type},#{content},#{images},#{status},#{createTime},#{updateTime})")
    public boolean save(BlogDaily blogDaily);
    @Delete("delete from tb_blog_daily where id = #{id}")
    public boolean delete(Long id);
    @Update("update tb_blog_daily set likes=likes+1 where id = #{id}")
    boolean addLike(Long id);
    @Update("update tb_blog_daily set likes=likes-1 where id = #{id}")
    boolean subLike(Long id);
    @Select("select * from tb_blog_daily where id < #{start} and status<2 order by createTime DESC,id DESC limit 6")
    public List<BlogDaily> getDailys(Long start);

    @Select("select * from tb_blog_daily where status < 2 order by likes DESC, comments DESC, createTime DESC limit 3")
    public List<BlogDaily> getHotDailies();

    @Select("select * from tb_blog_daily where (content like concat('%', #{searchKeyWord}, '%')) and type = #{type} and status<2")
    public List<BlogDaily> getSearchDailies(String searchKeyWord, Short type);

    @Select("select * from tb_blog_daily where content like concat('%', #{searchKeyWord}, '%') and status<2")
    public List<BlogDaily> getAllSearchDailies(String searchKeyWord);

    @Select("select * from tb_blog_daily where type = #{type} and status<2 limit 6")
    public List<BlogDaily> getByType(Short type);

    @Update("update tb_blog_daily set status = 1 where id = #{id}")
    public boolean reportBlog(Long id);
}
